package com.mszlu.rpc.consumer.controller;

import com.dai.rpc.annotation.MyReference;
import com.mszlu.rpc.consumer.rpc.GoodsHttpRpc;
import com.mszlu.rpc.provider.service.GoodsService;
import com.mszlu.rpc.provider.service.modal.Goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("consumer")
public class ConsumerController {

    @Autowired
    private RestTemplate restTemplate;

   /* @Autowired
    private GoodsHttpRpc goodsHttpRpc;

    @GetMapping("/goods/{id}")
    public Goods findGood(@PathVariable Long id){
        // return restTemplate.getForObject("http://localhost:7777/provider/goods/" + id,Goods.class);
        Goods goods = goodsHttpRpc.findGoods(id);
        return goods;
    }*/

    // 使用自定义注解
    @MyReference(version = "1.0")
    private GoodsService goodsService;

    @GetMapping("/goods/{id}")
    public Goods findGood(@PathVariable Long id){
        // return restTemplate.getForObject("http://localhost:7777/provider/goods/" + id,Goods.class);
        Goods goods = goodsService.findGoods(id);
        return goods;
    }

}
